project(dssi_plugin)

IF(NOT FAUST_EXECUTABLE)
  MESSAGE(STATUS "Looking for FAUST")
  FIND_PROGRAM(FAUST_EXECUTABLE faust)
  IF(FAUST_EXECUTABLE)
    MESSAGE(STATUS "Looking for FAUST -- ${FAUST_EXECUTABLE}")
  ENDIF(FAUST_EXECUTABLE)
ENDIF(NOT FAUST_EXECUTABLE)

IF(FAUST_EXECUTABLE)
  MACRO(FAUST_FILE FILENAME)
    GET_FILENAME_COMPONENT(PATH "${FILENAME}" PATH)
    GET_FILENAME_COMPONENT(HEAD "${FILENAME}" NAME_WE)
    SET(OUTFILE "${CMAKE_CURRENT_SOURCE_DIR}/${HEAD}.dsp.in")
    ADD_CUSTOM_COMMAND(
      OUTPUT "${OUTFILE}"
      COMMAND "${FAUST_EXECUTABLE}"
      ARGS -o ${OUTFILE}
      "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}"
      DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}")
    SET_SOURCE_FILES_PROPERTIES("${OUTFILE}" PROPERTIES GENERATED TRUE)
  ENDMACRO(FAUST_FILE)
ENDIF(FAUST_EXECUTABLE)

SET(BUILD_SHARED_LIBS ON)

SET(Libraries dl m)

FAUST_FILE(organ.dsp)
ADD_LIBRARY(organ organ_synth.cpp organ.dsp.in)
TARGET_LINK_LIBRARIES(organ ${Libraries})
